let Edu = require('../model/education')
let result = require('../utils/result')
let format = require('../utils/format.js')

function EduController() {

};


EduController.prototype.create = async (req, res) => {
    let uid = req.body.uid;
    let school = req.body.school;
    let speciality = req.body.speciality;
    let record = req.body.record;
    let end_time = req.body.end_time;
    let start_time = req.body.start_time;

    if (!uid || !school || !speciality || !record || !end_time || !start_time) {
        res.json(result(-1, '信息填写不完整'))
    } else {
        let edu = await Edu.findOne({where: {uid: uid}});
        if (edu) {
            Edu.update({
                school,
                speciality,
                record,
                end_time,
                start_time
            },{where: {uid:uid}});
        }else {
            Edu.create({
                school,
                speciality,
                record,
                end_time,
                start_time,
                uid
            });
            res.json(result(0,'success'))
        }
    }

};

EduController.prototype.getEdu = async (req, res) => {
    let uid = req.body.uid;
    Edu.findOne({where:{uid}}).then(rsp=>{
        res.json(result(0,'success',rsp))
    }).catch(err=>{
        res.json(result(-1, 'fail'))
    })
};




let eduController = new EduController();
module.exports = eduController
